<template>
  <div class="novels-view">
    <div class="view-header">
      <div class="header-content">
        <div class="header-text">
          <div class="title-container">
            <div class="title-icon">📚</div>
            <h2>{{ t('novel.world') }}</h2>
            <div class="title-decoration"></div>
          </div>
          <div class="subtitle-container">
            <p class="main-subtitle">{{ t('novel.exploreClassics') }}</p>
            <div class="subtitle-highlights">
              <span class="highlight-tag">{{ t('novel.immersiveExperience') }}</span>
              <span class="highlight-tag">{{ t('novel.intelligentDialogue') }}</span>
              <span class="highlight-tag">{{ t('novel.multiCharacter') }}</span>
            </div>
          </div>
        </div>
        <div class="header-stats">
          <div class="stat-item">
            <div class="stat-icon">📖</div>
            <div class="stat-content">
              <span class="stat-number">{{ novels.length }}</span>
              <span class="stat-label">{{ t('novel.novels') }}</span>
              <div class="stat-progress">
                <div class="progress-bar" style="width: 85%"></div>
              </div>
            </div>
          </div>
          <div class="stat-item">
            <div class="stat-icon">👥</div>
            <div class="stat-content">
              <span class="stat-number">{{ allCharactersCount }}</span>
              <span class="stat-label">{{ t('novel.characters') }}</span>
              <div class="stat-progress">
                <div class="progress-bar" style="width: 92%"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="novels-container">
      <div class="novels-grid">
        <NovelCard
          v-for="novel in novels"
          :key="novel.id"
          :novel="novel"
          @select="$emit('selectNovel', $event)"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import type { Novel } from '../../types/novel'
import NovelCard from './NovelCard.vue'

interface Props {
  novels: Novel[]
}

const props = defineProps<Props>()
const { t } = useI18n()

defineEmits<{
  selectNovel: [novel: Novel]
}>()

const allCharactersCount = computed(() => {
  return props.novels.reduce((total, novel) => total + (novel.characters?.length || 0), 0)
})
</script>

<script lang="ts">
export default {
  name: 'NovelsView'
}
</script>

<style scoped>
.novels-view {
  padding: 0;
  min-height: 100vh;
  overflow-y: auto;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
}

.novels-view::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.12) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(118, 75, 162, 0.15) 0%, transparent 70%),
    radial-gradient(circle at 10% 80%, rgba(255, 255, 255, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(255, 255, 255, 0.08) 0%, transparent 45%);
  pointer-events: none;
  z-index: 1;
  animation: backgroundShift 15s ease-in-out infinite;
}

@keyframes backgroundShift {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

.novels-view::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    linear-gradient(45deg, transparent 48%, rgba(255, 255, 255, 0.02) 50%, transparent 52%),
    linear-gradient(-45deg, transparent 48%, rgba(255, 255, 255, 0.02) 50%, transparent 52%);
  background-size: 30px 30px;
  pointer-events: none;
  z-index: 1;
  animation: meshMove 25s linear infinite;
}

@keyframes meshMove {
  0% { transform: translate(0, 0); }
  100% { transform: translate(30px, 30px); }
}

.view-header {
  padding: 80px 0 60px;
  background: transparent;
  color: white;
  position: relative;
  z-index: 2;
  overflow: hidden;
  width: 100%;
}

.view-header::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: 
    repeating-linear-gradient(
      45deg,
      transparent,
      transparent 2px,
      rgba(255, 255, 255, 0.05) 2px,
      rgba(255, 255, 255, 0.05) 4px
    ),
    repeating-linear-gradient(
      -45deg,
      transparent,
      transparent 3px,
      rgba(255, 255, 255, 0.03) 3px,
      rgba(255, 255, 255, 0.03) 6px
    );
  animation: floatPattern 25s linear infinite;
  z-index: -1;
}

@keyframes floatPattern {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

.view-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: #f5f7fa;
  border-radius: 40px 40px 0 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin: 0;
  position: relative;
  z-index: 3;
  backdrop-filter: none;
  background: transparent;
  border-radius: 0;
  padding: 30px 40px;
  border: none;
  box-shadow: none;
}

.title-container {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  position: relative;
}

.title-icon {
  font-size: 48px;
  animation: titleIconFloat 4s ease-in-out infinite;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
}

@keyframes titleIconFloat {
  0%, 100% { 
    transform: translateY(0px) rotate(0deg) scale(1); 
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.2));
  }
  50% { 
    transform: translateY(-8px) rotate(5deg) scale(1.05); 
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.3));
  }
}

.header-text h2 {
  font-size: 42px;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 50%, #ffffff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  letter-spacing: -0.5px;
}

.title-decoration {
  flex: 1;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.title-decoration::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.8), transparent);
  animation: decorationFlow 3s ease-in-out infinite;
}

@keyframes decorationFlow {
  0% { left: -100%; }
  100% { left: 100%; }
}

.subtitle-container {
  margin-bottom: 8px;
}

.main-subtitle {
  font-size: 22px;
  margin: 0 0 16px 0;
  opacity: 0.95;
  font-weight: 500;
  line-height: 1.4;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle-highlights {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.highlight-tag {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(10px);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
  animation: tagGlow 3s ease-in-out infinite;
}

.highlight-tag:nth-child(1) { animation-delay: 0s; }
.highlight-tag:nth-child(2) { animation-delay: 1s; }
.highlight-tag:nth-child(3) { animation-delay: 2s; }

@keyframes tagGlow {
  0%, 100% { 
    background: rgba(255, 255, 255, 0.25);
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.2);
  }
  50% { 
    background: rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 16px rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
  }
}

.header-stats {
  display: flex;
  gap: 40px;
}

.header-stats .stat-item {
  display: flex;
  align-items: center;
  gap: 20px;
  background: rgba(255, 255, 255, 0.2);
  padding: 28px 32px;
  border-radius: 28px;
  backdrop-filter: blur(20px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
  overflow: hidden;
  box-shadow: 
    0 15px 50px rgba(0, 0, 0, 0.2),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
  min-width: 200px;
}

.header-stats .stat-item:hover {
  transform: translateY(-8px) scale(1.08);
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 
    0 20px 60px rgba(0, 0, 0, 0.25),
    inset 0 3px 0 rgba(255, 255, 255, 0.5);
  border-color: rgba(255, 255, 255, 0.6);
}

.stat-icon {
  font-size: 36px;
  animation: statIconPulse 3s ease-in-out infinite;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}

@keyframes statIconPulse {
  0%, 100% { 
    transform: scale(1) rotate(0deg); 
    filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
  }
  50% { 
    transform: scale(1.1) rotate(5deg); 
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4));
  }
}

.stat-content {
  flex: 1;
  text-align: left;
}

.header-stats .stat-number {
  display: block;
  font-size: 44px;
  font-weight: 900;
  margin-bottom: 4px;
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.header-stats .stat-label {
  font-size: 16px;
  font-weight: 600;
  opacity: 0.9;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  margin-bottom: 8px;
}

.stat-progress {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.6));
  border-radius: 3px;
  transition: width 2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.progress-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  animation: progressShine 2s ease-in-out infinite;
}

@keyframes progressShine {
  0% { left: -100%; }
  100% { left: 100%; }
}

.novels-container {
  padding: 40px;
  background: #f5f7fa;
  min-height: 60vh;
}

.novels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 32px;
  max-width: 1200px;
  margin: 0 auto;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .novels-grid {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
  }
  
  .header-content {
    flex-direction: column;
    gap: 24px;
    text-align: center;
  }
  
  .header-stats {
    gap: 24px;
  }
}

@media (max-width: 768px) {
  .novels-container {
    padding: 20px;
  }
  
  .novels-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .view-header {
    padding: 40px 20px 30px;
  }
  
  .header-content {
    padding: 20px 24px;
  }
  
  .header-text h2 {
    font-size: 28px;
  }
  
  .header-stats {
    flex-direction: row;
    gap: 16px;
  }
  
  .header-stats .stat-item {
    padding: 16px 20px;
  }
}
</style> 